(function(){var t=window.BX;if(t.IblockSelectorElement){return}t.IblockSelectorElement=function(){this.id="";this.filter=[]};t.IblockSelectorElement.create=function(e,i){var n=new t.IblockSelectorElement;n.initialize(e,i);return n};t.IblockSelectorElement.prototype={initialize:function(e,i){this.id=e;this.settings={defaultFilter:[],internalFilter:[],quickSearchField:""};if(t.type.isPlainObject(i)){if(t.type.isArray(i.defaultFilter))this.settings.defaultFilter=i.defaultFilter;if(t.type.isArray(i.internalFilter))this.settings.internalFilter=i.internalFilter;if(t.type.isNotEmptyString(i.quickSearchField))this.settings.quickSearchField=i.quickSearchField}this.loadFilter();t.addCustomEvent("BX.Main.Filter:apply",t.proxy(this.applyFilter,this));t.addCustomEvent(t.UI.ButtonPanel,"button-click",function(e){var i;if(t.type.isNotEmptyObject(e)){if(e.TYPE==="save"){top.BX.SidePanel.Instance.postMessageTop(window,"save",{filter:this.filter});i=top.BX.SidePanel.Instance.getSliderByWindow(window);if(i){i.close(true);top.BX.SidePanel.Instance.destroy(i.getUrl())}i=null}}}.bind(this))},loadFilter:function(){var e,i,n,r;this.filter=this.settings.defaultFilter;e=t.Main.filterManager.getById(this.id);if(e!==null){i=e.getPreset().getCurrentPresetData();n=[].concat(i.FIELDS,i.ADDITIONAL);r=e.getSearch().prepareSquaresData(n);this.filter=r.map(function(i){var r=n.find(function(t){return t.NAME===i.value&&!e.getPreset().isEmptyField(t)}),l;l={name:i.name,key:r.NAME,value:r.VALUE||r.VALUES};if(t.type.isString(l.value)){l.value={VALUE:l.value}}if(t.type.isPlainObject(r.SUB_TYPE)){l.value.SUB_TYPE=r.SUB_TYPE.VALUE}return l});this.loadQuickSearch()}if(this.settings.internalFilter.length>0)this.filter=[].concat(this.settings.internalFilter,this.filter);if(this.filter.length===0)this.filter=this.settings.defaultFilter},loadQuickSearch:function(){var e,i,n,r,l,a,s,f,c=false;if(this.settings.quickSearchField==="")return;e=t.Main.filterManager.getById(this.id);if(e!==null){r=e.getPreset().getCurrentPresetData();l=[].concat(r.FIELDS,r.ADDITIONAL);n=e.getSearch().getSearchString();if(n!==""){i=this.settings.quickSearchField;f={VALUE:n,QUICK_SEARCH:"Y"};s=l.find(function(t,e,n){return t.NAME===i});s=s.LABEL+": ";if(this.filter.length>0){a=this.filter.findIndex(function(t,e,n){return t.key===i});if(a>-1){c=true;this.filter[a].name=s+n;this.filter[a].value=f}}if(!c){this.filter.push({name:s+n,key:i,value:f})}}}},applyFilter:function(t,e,i,n,r){if(t!==this.id){return}this.loadFilter()}}})();
//# sourceMappingURL=script.map.js